Fix unmasking issue in download_ee_image function #1977
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I found a bug when using the function geemap.download_ee_image.
Before the proposed fix, if the input image has zero values, they will be used to updat the mask of the input image, which looks to be undesirable. In addition, calling unmask before calling clip does not look to make sense.
I did not tested the proposed fix extensively but I'm providing an example with Google Dynamic World. I had problem trying to save images of this dataset since it has valid zero values.
This is the correct output:
Trying to export this image with the current code. Here I set unmask_value to 255, since 0 is a valid class in Google Dynamic World. I also use the parameter
set_nodata
to avoidgeedim
to set 0 as the ndata value (it's the default option for uint8 dtype).The output of this code is a tif file in which the zero class become equal to 255 and the areas outside the polygons used to clip the image become 0. With the proposed the change, the exported image looks correct.
Below I'm providing a code to plot the images.
The output images:
Original image (before fix)
plot('ee_image.tif')
Image with proposed fix
plot('ee_image.tif')